// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
   catelist:["男装","女装","零食","家电","床上用品","家具"],
   bannerlist:[{
     url:"../../images/banner1.jpg"
   },{
     url:"../../images/banner2.jpg"
   },{
     url:"../../images/banner3.jpg"
   }],
   latitude:"",
   longitude:"",
   danmulist:[{
     text:"网院",
     color:"#ff0000",
     time:5
   },{
     text:"网院",
     color:"#ff0000",
     time:10
   }
  ],
  books:[
    {id:0,title: "红楼梦", price:39.8},
    {id:1, title: "西游记", price: 42.5 },
    {id:2, title: "水浒传", price: 36.7 },
    {id:3,title: "三国演义", price: 38.8 }
  ],


  },
  onLoad() {
    
    },
    saveUserInfo:function(){
        var data ={"name":"自己的姓名","student_id":"201965110447"}
        wx.setStorageSync('userinfo', data)
        wx.setStorage({
          key:"studentinfo",
          data:{"sex":"男","age":18}
        })
    },
    getUserInfo:function(){
      var studentinfo = wx.getStorageSync('studentinfo')
      console.log(studentinfo);
      wx.getStorage({
        key: 'userinfo',
        success(res){
          console.log(res);
        }
        
      })
      //获取小程序中所有的缓存信息(Key)
      wx.getStorageInfo({
        success: (option) => {
          console.log(option)
        },
      })

    },
    removeUserInfo:function(){
        //异步移除
        wx.removeStorage({
          key: 'userinfo',
        })
        wx.removeStorageSync('studentinfo');
    },
    getLocal:function(){
      var then = this;
      wx.getLocation({
        type:"gcj02",
        success(res){
          then.setData({
            latitude:res.latitude,
            longitude:res.longitude
          })
        }
      })

    },
    selectImage:function(){
      wx.chooseImage({
        count: 1,
        sourceType:['camera'],
        success(res){
        console.log(res);
        wx.previewImage({
          urls: [res.tempFilePaths[0]],
        })
        wx.getImageInfo({
          src: [res.tempFilePaths[0]],
          success(res){
            console.log(res)

          }
        })
      }
      })
    },
    saveImage:function(){
      wx.saveImageToPhotosAlbum({
        filePath: "http://tmp/Th73dnwKwFgj6005ecfdeca19f2e55afd12e27685782.jpg",
      })
    },
    openMap:function(){
      var then = this;
      wx.openLocation({
        latitude: then.data.latitude,
        longitude: then.data.longitude,
        name:"湖南开放大学终教楼1104",
        address:"湖南省长沙市天心区青园路168号1104"
      })
    },
    call:function(){
wx.makePhoneCall({
  phoneNumber: '111111',
})
    },
    scanCode:function(){
      wx.scanCode({
        onlyFromCamera: true,
        success(res){
          console.log(res)
        }
      })
    },
    vibrateLong:(res)=>{
      var then = this;
    wx.vibrateLong({
      
  success: (res) => {
    console.log(res)
  },
  searchContacts:function(){
    wx.searchContacts({
     
      success (res) {
        console.log(res);
      },
      fail: console.error,
    })
  },
  chooseContact:function(){
  wx.searchContacts({
  phoneNumber: '10000000',
  success (res) {},
  fail: console.error,
})
  },
})
    },
    selectLocal:function(){
      var then = this ;
      wx.chooseLocation({
        latitude: then.data.latitude,
        longitude:then.data.longitude,
      })

    },
    
    checkboxChange:function(e){
      var then = this;
      var likestr = "";
      for (let index = 0; index < e.detail.value.length; index++) {
        likestr= likestr+e.detail.value[index];
        
      }
      then.setData({
        likes:likestr
      })
   
      console.log(e)
      console.log(e.detail.value[0])
    },
})

var pageData={}
  pageData.data={
    color:'black',
    colorArray:['red','blue','yellow','green','black']
  }
  for(var i = 0;i<5;++i){
    (function(index){
      pageData['bindtap'+index]=function(e){
        this.setData({
          color:this.data.colorArray[index]
        })
      }
    })(i)
  }
 
